//pack11jsclass

var DekaroMap = new google_map();

function google_map() {

    this.element=null;
    this.map=null;
    this.MapActivated=false;

    this.init = function() {

        if(DekaroMap.MapActivated) return true;

        try {
            this.element=document.getElementById("google_map");
            this.element.className="google_map";
        } catch(e) { Trace("google_map not found so ..."); }
        cou=0;
        /*while(this.element.offsetWidth==0 && cou<200) {
            Trace(this.element.offsetWidth+" - "+this.element.offsetHeight);
            cou++;
        }*/
        
        try { this.map=new GMap2(this.element); } catch(e) { Trace("Gmap2 doesnt work"); }
        try { mapdata=document.getElementById("google_data").value; } catch(e) { Trace("google_data not found"); return; }
            var data=mapdata.split(", ");

        try {
            var map=this.map;
 

        this.map.setCenter(new GLatLng(data[0], data[1]), 13);
        this.map.addControl(new GLargeMapControl());
        mapStyle=new GMapTypeControl();
        this.map.addControl(mapStyle);
        //this.element.className="google_map";

        icon = new GIcon(G_DEFAULT_ICON);
        icon.image = "images/mapicon.png";
        icon.shadow = "images/mapshadow.png";
        icon.iconSize = new GSize(32, 32);
        icon.shadowSize = new GSize(46, 32);
        icon.iconAnchor = new GPoint(16, 32);

        markerOptions = { icon:icon };
        this.map.addOverlay(new GMarker(this.map.getCenter(), markerOptions));
        DekaroMap.MapActivated=true;
       } catch(e) {
            Trace("cant build map");
            Trace(e);
            return false;
        }

        Trace(this.element.offsetWidth+" - "+this.element.offsetHeight);
        //ObjectCardNavigation.mapLoaded();
    }

    this.add = function() {

        //alert("add");

        try {
            this.element=document.getElementById("google_map");
            this.map=new GMap2(this.element);
            mapdata=document.getElementById("google_data").value;
            data=mapdata.split(", ");
        } catch(e) {
            return false;
        }

        map=this.map;

        this.map.setCenter(new GLatLng(data[0], data[1]), 13);
        this.map.addControl(new GLargeMapControl());
        mapStyle=new GMapTypeControl();
        this.map.addControl(mapStyle);
        this.element.className="google_map";

        icon = new GIcon(G_DEFAULT_ICON);
        icon.image = "images/mapicon.png";
        icon.shadow = "images/mapshadow.png";
        icon.iconSize = new GSize(32, 32);
        icon.shadowSize = new GSize(46, 32);
        icon.iconAnchor = new GPoint(16, 32);

        markerOptions = { icon:icon, draggable: true };

        var marker = new GMarker(this.map.getCenter(), markerOptions);

        GEvent.addListener(marker, "dragend", function() {
            document.getElementById("google_data").value=marker.getLatLng();
            //alert(marker.getLatLng());
        });

        this.map.addOverlay(marker);
    }
}

function buildMap() {

        map=new GMap2(document.getElementById("google_map"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 8);
        map.addControl(new GLargeMapControl());
        map.openInfoWindowHtml(map.getCenter(), "Hello fucking world!");
}